package com.hb.trade.server.project.section.service.raw.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.unit.DataUnit;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hb.core.pojo.parent.PageResult;
import com.hb.core.pojo.project.section.dto.ClarifyDTO;
import com.hb.core.pojo.project.section.dto.ClarifyTemplateDTO;
import com.hb.core.pojo.project.section.entity.Clarify;
import com.hb.core.pojo.project.section.mapper.ClarifyMapper;
import com.hb.trade.server.project.section.service.raw.ClarifyService;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 澄清答疑表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2021-10-09
 */
@Service
public class ClarifyServiceImpl extends ServiceImpl<ClarifyMapper, Clarify> implements ClarifyService {

    @Override
    public boolean getReplyFlag(String id) {
        return baseMapper.getReplyFlag(id) > 0;
    }


    @Override
    public PageResult<ClarifyDTO> findBidderClarifyList(ClarifyDTO clarifyDTO) {
        Page<ClarifyDTO> clarifyConfirmDTOPage = baseMapper.findBidderClarifyList(clarifyDTO.pages(), clarifyDTO.getProjectId(),clarifyDTO.getSectionId(), clarifyDTO.getTenderId());
        return PageResult.get(clarifyConfirmDTOPage);
    }

    /**
     * 招标人查询 澄清/补遗列表 需要返回标段名称和标段ID
     * @param clarifyDTO
     * @return
     */
    @Override
    public Page<ClarifyDTO> pageClarify(ClarifyDTO clarifyDTO) {
        Page<ClarifyDTO> clarifyConfirmDTOPage = baseMapper.pageClarify(clarifyDTO.pages(), clarifyDTO);
        return clarifyConfirmDTOPage;
    }

    /**
     * 根据标段列表查询改标段下的已发布澄清公告信息
     * @param sectionId
     * @return
     */
    @Override
    public List<ClarifyDTO> listClarifyBySectionId(Long sectionId) {
        List<ClarifyDTO> listClarifyDTO = baseMapper.listClarifyBySectionId(sectionId);

        return listClarifyDTO;
    }

    /**
     * @Description: 查询投标人澄清回执word模版需要的信息
     *
     * { 澄清代理公司、 项目名称、 当前时间(xxxx年xx月xx日)、 回执企业 }
     *
     * @author yuezheng
     * @param
     * @return org.fzzn.core.model.msg.ResponseDto
     * @date 2022/5/23 13:48
     */
    @Override
    public ClarifyTemplateDTO findClarifyTemplateInfo(ClarifyDTO clarifyDTO) {
        Clarify clarify = baseMapper.selectById(clarifyDTO.getId());
        ClarifyTemplateDTO clarifyTemplateDTO = baseMapper.selectClarifyTemplateInfo(clarify);
        String currentDate = DateUtil.format(new Date(), "yyyy年mm月dd日");
        clarifyTemplateDTO.setCurrentTime(currentDate);
        return clarifyTemplateDTO;
    }
}
